﻿package mortal.game.view.rebate.openNewSerSevenDay.active2
{
    import com.mui.controls.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.palyer.data.*;
    import mortal.game.view.rebate.data.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;
    import mortal.mvc.core.*;

    public class OpenNewSerSevTop2 extends GSprite
    {
        protected var _mbg:GImageBitmap;
        protected var _dayNum:BitmapNumberText;
        protected var _dayTitle:GImageBitmap;
        protected var _day:BitmapNumberText;
        protected var _hour:BitmapNumberText;
        protected var _min:BitmapNumberText;
        protected var _activeTime:GTextFiled;
        protected var _actRule:GTextFiled;
        protected var _openBtn:GLoadingButton;
        protected var _secView:SecTimerView;
        private var targetTypeNameStrObj:Object;

        public function OpenNewSerSevTop2()
        {
            this.targetTypeNameStrObj = {10:8, 11:9, 12:10, 13:11};
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._mbg = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2Bg, 0, 0, this);
            this._dayNum = UIFactory.bitmapNumberText(139, 22, "OpenNewSerSevNum.png", 38, 43, -18, this, 9, 1);
            this._dayNum.text = "5";
            this._dayTitle = UIFactory.gImageBitmap(ImagesConst.openNewSerSevDayAct2TopT8, 339, 17, this);
            this._day = UIFactory.bitmapNumberText(142, 201, "investmentNum.png", 24, 30, -7, this, 9, 1);
            this._day.text = "07";
            this._hour = UIFactory.bitmapNumberText(205, 201, "investmentNum.png", 24, 30, -7, this, 9, 1);
            this._hour.text = "23";
            this._min = UIFactory.bitmapNumberText(284, 201, "investmentNum.png", 24, 30, -7, this, 9, 1);
            this._min.text = "59";
            this._activeTime = UIFactory.gTextField("" + Language.getString(71795), 17, 233, 500, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._actRule = UIFactory.gTextField("" + Language.getString(71796), 18, 250, 500, 20, this, GlobalStyle.textFormatPutong.setColor(16777215));
            this._openBtn = UIFactory.gLoadingButton(ImagesConst.OpenNewSerSevDayAct2GoBtn_upSkin, 492, 221, 131, 39, this);
            this._openBtn.label = "";
            this._secView = new SecTimerView();
            this._secView.addEventListener(EventName.SecViewTimeChange, this.onTimeChangeHd);
            this._openBtn.configEventListener(MouseEvent.CLICK, this.onOpen);
            this.upateTime();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._mbg = null;
            this._dayNum = null;
            this._dayTitle = null;
            this._day = null;
            this._hour = null;
            this._min = null;
            this._activeTime = null;
            this._actRule = null;
            this._openBtn = null;
            this._secView = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function upateTime() : void
        {
            var _loc_2:int = 0;
            var _loc_1:* = ClockManager.instance.serverOpenDateNum;
            if (_loc_1 >= 8 && _loc_1 <= 11)
            {
                _loc_2 = RebateUtil.getTargetType();
                this._dayTitle.imgUrl = "openNewSerSevDayAct2TopT" + this.targetTypeNameStrObj[_loc_2];
            }
            this._dayNum.text = "" + _loc_1;
            this._activeTime.text = Language.getString(71795) + OpenServerSevenDayUtil.getTodayFullString();
            this.setTimeCountDown();
            return;
        }// end function

        private function onOpen(event:MouseEvent) : void
        {
            var _loc_2:* = ClockManager.instance.serverOpenDateNum;
            var _loc_3:* = PlayerConst.TabType_DragonSoul;
            switch(_loc_2)
            {
                case 8:
                {
                    _loc_3 = PlayerConst.TabType_DragonSoul;
                    break;
                }
                case 9:
                {
                    _loc_3 = PlayerConst.TabType_HolyBook;
                    break;
                }
                case 10:
                {
                    _loc_3 = PlayerConst.TabType_WarShield;
                    break;
                }
                case 11:
                {
                    _loc_3 = PlayerConst.TabType_MonsterSoul;
                    break;
                }
                default:
                {
                    break;
                }
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.PlayerModuleShowIndexByType, _loc_3));
            return;
        }// end function

        protected function setTimeCountDown() : void
        {
            var _loc_1:* = this.getLeftTime();
            this._secView.stop();
            if (_loc_1 < 0)
            {
                return;
            }
            this._secView.setLeftTime(_loc_1);
            return;
        }// end function

        protected function getLeftTime() : Number
        {
            return RebateUtil.getTodayLeftTime();
        }// end function

        protected function onTimeChangeHd(event:DataEvent) : void
        {
            if (this._secView == null)
            {
                return;
            }
            if (this._secView.secTimerViewData == null)
            {
                this._secView.stop();
                return;
            }
            var _loc_2:* = this._secView.secTimerViewData.dd();
            var _loc_3:* = this._secView.secTimerViewData.hh();
            var _loc_4:* = this._secView.secTimerViewData.mm();
            var _loc_5:* = this._secView.secTimerViewData.ss();
            if (_loc_2.length == 2 && _loc_2 == "0")
            {
                _loc_2 = _loc_2.substring(1);
            }
            this._day.text = "" + _loc_2;
            this._hour.text = "" + _loc_3;
            this._min.text = "" + _loc_4;
            return;
        }// end function

    }
}
